package com.yang.springcloud.controller;

import com.yang.springcloud.pojo.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
@RequestMapping("/customer")
public class DeptCustomerController {


    @Autowired
    private RestTemplate restTemplate;


    //private static final  String REST_URL_PREFIX = "http://localhost:8001";
    private static final  String REST_URL_PREFIX = "http://springcloud-provider-dept";

    @GetMapping("/dept/add")
    public Boolean add(Dept dept){
        return restTemplate.postForObject(REST_URL_PREFIX + "/dept/add/",dept,Boolean.class);
    }

    @RequestMapping("/dept/queryList")
    public List<Dept> queryList(){
        return restTemplate.getForObject(REST_URL_PREFIX + "/dept/queryList/",List.class);
    }

    @RequestMapping("/dept/get/{id}")
    public Dept get(@PathVariable("id") Long id){
        return restTemplate.getForObject(REST_URL_PREFIX + "/dept/queryById/" + id,Dept.class);
    }

}
